package producer.broker;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * Created with IDEA
 * Author: LuoHengYi
 * Date: 2022/6/18
 * Time: 13:37
 */
@Slf4j
public class AsyncBaseQueue {

    private static final int THREAD_SIZE = Runtime.getRuntime().availableProcessors();


    private static final int QUEUE_SIZE = 1000;


    private static ExecutorService senderAsync =
            new ThreadPoolExecutor(
                    THREAD_SIZE,
                    THREAD_SIZE,
                    60,
                    TimeUnit.SECONDS,
                    new ArrayBlockingQueue<>(QUEUE_SIZE),
                    new ThreadFactory() {

                        @Override
                        public Thread newThread(Runnable r) {
                            Thread t = new Thread(r);
                            t.setName("rabbitmq_client_async_sender");
                            return t;
                        }
                    },
                    (r, executor) -> log.error("async sender is error rejected, runable:{},executor:{}",r,executor));

    public static void submit(Runnable runnable){
        senderAsync.submit(runnable);
    }
}
